<template>
  <div id="safe_audit">
    <h2 style="text-align: center">入库申请</h2>
    <!--    入库申请-->
    <el-table :data="arrList1" style="width: 100%">
      <el-table-column prop="purchaseId" label="采购订单id" width="150">
      </el-table-column>
      <el-table-column prop="purchaseOrderNumber" label="采购订单编号" width="150">
      </el-table-column>
      <el-table-column prop="supplierId" label="供货商id" width="150">
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="totalPrice" label="总金额" width="150">
      </el-table-column>
      <el-table-column prop="totalAmount" label="总数量" width="150">
      </el-table-column>
      <el-table-column prop="register" label="登记人" width="150">
      </el-table-column>
      <el-table-column prop="payMethod" label="支付方式" width="150">
        <template slot-scope="scope">
          {{ scope.row.payMethod == "P002-1" ? "余额支付" : (scope.row.payMethod == "P002-2" ? "微信支付" : "现金支付") }}
        </template>
      </el-table-column>
      <el-table-column prop="conveyTag" label="配送标志" width="150">
        <template slot-scope="scope">
          {{ scope.row.conveyTag == "P001-1" ? "待发货" : (scope.row.conveyTag == "P001-2" ? "待收货" : "已收货 ") }}
        </template>
      </el-table-column>
      <el-table-column prop="checkTag" label="审核状态" width="150">
        <template slot-scope="scope">
          {{ scope.row.checkTag == "S001-3" ? "审核通过" : (scope.row.checkTag == "S001-2" ? "审核未通过" : "等待审核") }}
        </template>
      </el-table-column>
      <!--操作列-->
      <el-table-column label="入库调度" style="width: 50%">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showById(scope.row.purchaseId)">入库申请</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 入库申请弹出对话框 -->
    <el-dialog title="入库申请" :visible.sync="dialogVisible" width="60%">
      <el-form :inline="true" :model="filebean" class="demo-form-inline">
        <el-form-item label="采购订单编号">
          <el-input v-model="filebean.purchaseOrderNumber" placeholder="采购订单编号"></el-input>
        </el-form-item>
        <el-form-item label="供货商id">
          <el-input v-model="filebean.supplierId" placeholder="供货商id"></el-input>
        </el-form-item>
        <el-form-item label="总数量">
          <el-input v-model="filebean.totalAmount" placeholder="总数量"></el-input>
        </el-form-item>
        <el-form-item label="总价格">
          <el-input v-model="filebean.totalPrice" placeholder="总价格"></el-input>
        </el-form-item>
         <el-form-item label="登记时间">
        <el-input v-model="filebean.registerTime" class="demo-ruleForm" autocomplete="off" readonly></el-input>
      </el-form-item>
        <el-form-item label="入库人">
          <el-input v-model="filebean.storer" placeholder="请输入入库人"></el-input>
        </el-form-item>
        <el-form-item label="入库理由">
          <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入入库理由"
              v-model="filebean.reason">
          </el-input>
        </el-form-item>
      </el-form>
      <el-table
          :data="tableData"
          style="width: 100%">
        <el-table-column
            prop="purchaseId"
            label="采购订单id"
            width="180">
        </el-table-column>
        <el-table-column
            prop="productId"
            label="商品id"
            width="180">
        </el-table-column>
        <el-table-column
            prop="count"
            label="采购数量">
        </el-table-column>
        <el-table-column
            prop="price"
            label="价格">
        </el-table-column>
        <el-table-column
            prop="subtotal"
            label="总价">
        </el-table-column>
        <el-table-column
            prop="gatherTag"
            label="入库标志">
          <template slot-scope="scope">
            {{ scope.row.gatherTag == "K001-3" ? "入库成功" : (scope.row.checkTag == "K001-2" ? "入库失败" : "等待入库") }}
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="add">制定入库单</el-button>
      </span>
    </el-dialog>

    <!---分页组件-->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                   :page-sizes="pageSizeList" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  created() {
    this.list()

  },
  data() {
    return {
      arrList1: [],
      tableData: [],
      info: {
        search_gatherId: '',
        search_storer: '',
        search_register: '',
        search_checkTime1: '',
        search_checkTime2: '',
      },
      // 当前页号
      currentPage: 1,
      // 当前页大小
      pageSize: 2,
      // 总记录数
      total: 0,
      // 页大小列表
      pageSizeList: [2, 5, 10, 20],
      dialogVisible: false,
      dialogVisibleCheck: false,
      dialogVisibleAdd: false,
      // 审核表单的对象
      addForm: {

      },
      //定义到对话框的值
      filebean: {

      },
      showGather: {

      },
      max:0,
      registerTime:"",
      checkTime:"",
      gatherList:{},
      gatherAry: {}
    }
  },
  methods: {
    async list() {
      const { data: res } = await this.$http.post
      (`/community/gather/purchaseOrderList2/${this.currentPage}/${this.pageSize}`)
      this.arrList1 = res.rows
      this.total = res.total
      let aaa=this.total/1
      if(aaa=="Infinity"){
        this.max=0
      }else{
        this.max=aaa
      }
    },
    async showById(id) {
        this.dialogVisible = true;
        const { data: res } = await this.$http.post(`/community/gather/showById2?purchaseId=`+id);
        this.filebean = res;

        const {data:ses} = await this.$http.post
        (`/community/gather/purchaseOrderById?id=`+id)
        this.tableData = ses
    },
    //制定入库单与入库申请单
    async add(){
      // console.log(this.filebean)
      // console.log(this.tableData)
      this.gatherList.storer = this.filebean.storer
      this.gatherList.reason = this.filebean.reason
      this.gatherList.totalAmount = this.filebean.totalAmount
      this.gatherList.totalPrice = this.filebean.totalPrice
      this.gatherList.purchaseId = this.filebean.purchaseId

      this.gatherList.supplierId = this.filebean.supplierId

      const gather=this.gatherList
      const details=this.tableData
      this.gatherAry = {
        gather,
        details
      }
      // const { data: res } =
      //     await this.$http.post(`/community/gather/add`,this.gatherAry);
          alert("制定入库单成功")

      console.log(this.arrList1)
      const purchaseId = this.arrList1[0].purchaseId
      console.log(purchaseId)
      //修改采购单的发货状态
      const { data: ses } =
          await this.$http.post(`/community/gather/updateById?id=`+purchaseId);

          //将已添加过入库单与入库明细单的数组设为空
      this.gatherAry = {}
      //隐藏入库面板
      this.dialogVisible = false;
      this.list()
    },

    // //修改
    // async edit() {
    //   //拿到仓库id
    //   let stockId = this.stockId
    //   let totalAmount = this.filebean.totalAmount
    //   let parameter = {
    //     stockId,
    //     totalAmount
    //   }
    //   this.getdatatime()
    //   const { data: res } = await this.$http.post
    //   (`/community/gather/add2`,parameter)
    //   alert("入库申请成功")
    // },
    // 页大小改变
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    // 页号改变
    handleCurrentChange(val) {
      this.currentPage = val
      // 重新查询
      this.list()
    },
  },
  // 表单查询
  search() {
    // 查询
    this.currentPage = 1
    this.list()
  },
}
</script>

<style></style>